from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone

# Create your models here.
class Role(models.Model):
    # 角色表
    name = models.CharField(max_length=30)

    class Meta:
        db_table = 'tb_role'
        verbose_name = '角色表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name



class User(AbstractUser):
    # 用户表
    # 用户手机号校验 unique=True 不能重复
    phone = models.CharField(max_length=11, null=True, unique=True, blank=True, verbose_name='用户手机')
    role = models.ManyToManyField(Role, verbose_name='所属角色')
    last_login = models.DateTimeField(default=timezone.now())
    class Meta:
        db_table = 'user'
    def __str__(self):
        return self.username